/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

#include "stdafx.h"
#include "FCHttpGetService.h"

namespace FaceCat{
    lstring FCHttpGetService::get(lstring url){
        lstring buffer = "";
        NSString *nUrl = [NSString stringWithUTF8String:url.c_str()];
        NSString *encodedValue = [nUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:encodedValue]];
        
        NSURLResponse * response = nil;
        NSError * error = nil;
        NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest
                                              returningResponse:&response
                                                          error:&error];
        if(data){
            NSString *nsStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            if(nsStr){
                return [nsStr UTF8String];
            }
        }
        return "";
    }
    
    String FCHttpGetService::get(String url){
        lstring sUrl = FCTran::StringTostring(url);
        lstring result = get(sUrl);
        String resultS = FCTran::stringToString(result);
        return resultS;
    }
}
